package Controller;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import DAO.AgentDao;
import DAO.BoxDao;
import DAO.BranchDao;
import DAO.GoodsDao;
import DAO.MessageResponseDao;
import DAO.ParcelDao;
import DAO.TerminalDao;
import POJO.Agent;
import POJO.BoxTypeStatusList;
import POJO.Branch;
import POJO.DevList;
import POJO.Goods;
import POJO.Parcel;
import POJO.Terminal;
import Utils.GenerateRandNumHelper;
import Utils.TimeHelper;

@Controller
@RequestMapping(value = "ebservice")
public class EbserviceController {

//	static Logger logger = Logger.getLogger(EbserviceController.class);

	static String BOOKING_SUCCESS = "00000";// 预定成功
	static String BOOKING_FAILURE = "00001";// 预定失败（箱格已满）
	static String QUERY_SUCCESS = "00002";// 查询成功
	static String QUERY_FAILURE = "00003";// 查询失败（订单号未知）
	static String CANCELORDER_SUCCESS = "00004";// 取消预订成功
	static String CANCELORDER_FAILURE_NOBOOK = "00005";// 取消预订失败（非预订状态）
	static String CANCELORDER_FAILURE_NOORDER = "00006";// 取消预订失败（未找到订单）
	static String COMMAND_SUCCESS = "00007";// 命令已经接收等待执行
	static String COMMAND_FAILURE_NOORDER = "00008";// 命令执行失败（未找到订单）
	static String COMMAND_FAILURE_TIMEOUT = "00009";// 命令执行失败（订单超时）
	static String COMMAND_FAILURE_NOGOODS = "00010";// 命令执行失败（订单还未有物品）
	static String COMMAND_FAILURE_GOODSGETTED = "00011";// 命令执行失败（订单物品已被取走）
	static String BOOKING_SUCCESS_TIMEOUT = "00012";// 预订成功（该单号已超时）
	static String BOOKING_FAILURE_TERMINALOFF = "00013";// 预订失败（设备不在线）
	static String BOOKING_SUCCESS_WAITTING = "00014";// 预定请求已接收，等待反馈。
	static String RESET_FAILURE = "00015";//重置成功
	static String RESET_SUCCESS = "00016";// 重置失败
	static String AUTH_ERROR = "E0001";// 身份校验失败
	static String PARAM_ERROR = "E0002";// 参数出错
	static String TIME_OUT = "E0003";// 请求超时
	static String ABNORMAL_ERROR = "E0009";// 异常（可重新请求）

	@Autowired
	GoodsDao goodsDao;
	@Autowired
	BoxDao boxDao;
	@Autowired
	AgentDao agentDao;
	@Autowired
	MessageResponseDao messageResponseDao;
	@Autowired
	TerminalDao terminalDao;
	@Autowired
	BranchDao branchDao;
	@Autowired
	ParcelDao parcelDao;

	/**
	 * 箱格预定接口
	 * 
	 * @param partnerID
	 * @param sign
	 * @param mobileNum
	 * @param userMobileNum
	 * @param orderNo
	 * @param period
	 * @param deviceSeq
	 * @param boxTypeId
	 * @param timestamp
	 * @return
	 */
	@RequestMapping("BoxOrder")
	@ResponseBody
	public Map<String, String> bookBox(
			@RequestParam("partnerID") String partnerID,
			@RequestParam("sign") String sign,
			@RequestParam("mobileNum") String mobileNum,
			@RequestParam("userMobileNum") String userMobileNum,
			@RequestParam("orderNo") String orderNo,
			@RequestParam("period") String p,
			@RequestParam("deviceSeq") String deviceSeq,
			@RequestParam("boxTypeID") String b,
			@RequestParam("timestamp") String t) {

		HashMap<String, String> response = new HashMap<String, String>();
		try {

			// 参数检查
			int period = Integer.parseInt(p);
			int boxTypeId = Integer.parseInt(b);
			long timestamp = Long.parseLong(t);
			// get terminalId by deviceSeq
			if(deviceSeq.length()!=12){
				throw new Exception();
			}
			int terminalId = Integer.parseInt(deviceSeq.substring(2));// 一期暂用terminalId，转换去掉YB留下整数
			// assign boxSeq by boxTypeId
			int boxNum = boxDao
					.getBoxSeqByCertainBoxType(boxTypeId, terminalId);
			// 验证请求是否超时
			if (TimeHelper.isNowLate(timestamp, 5)) {
				response.put("responseCode", TIME_OUT);
				response.put("response", "请求已超时");
				return response;
			}
			// varify agent
			Agent agent = agentDao.findByPartnerId(partnerID);
			agent.setTimestamp(timestamp);
			if (agent == null || !agent.varify(sign)) {
				response.put("responseCode", AUTH_ERROR);
				response.put("response", "身份校验失败");
				return response;
			}

			// 检查设备权限
			if (!isTerminalBelong(terminalId, agent.getId())) {
				response.put("responseCode", BOOKING_FAILURE);
				response.put("response", "预定失败(设备不在管辖范围或不存在)");
				return response;
			}

			// 检查设备是否离线
			Terminal terminal = terminalDao.get(terminalId);
			if (TimeHelper.isTerminalOff(terminal.getLoginTime())) {
				response.put("responseCode", BOOKING_FAILURE_TERMINALOFF);
				response.put("response", "预订失败（设备不在线）");
				return response;
			}

			// 检查订单号重复
			Goods testGoods = goodsDao.getGoodsByOrderNo(orderNo);

			if (boxNum == -1) {
				// 预定失败（箱格已满）
				response.put("responseCode", BOOKING_FAILURE);
				response.put("response", "预定失败(箱格已满)");
				return response;
			}

			if (testGoods != null) {
				if (testGoods.getStatus() == 0 || testGoods.getStatus() == 3) {
					response.put("responseCode", BOOKING_SUCCESS);
					response.put("response", "预定成功（该单号已存在且有效）");
					response.put("saveOpenCode", testGoods.getOpenCode());
					response.put("orderNo", testGoods.getOrderNo());
					response.put("boxNum",
							String.valueOf(testGoods.getBoxNum()));
					return response;
				} else {
					response.put("responseCode", BOOKING_SUCCESS_TIMEOUT);
					response.put("response", "预订失败（该单号存在但无效）");
					response.put("saveOpenCode", testGoods.getOpenCode());
					response.put("orderNo", testGoods.getOrderNo());
					response.put("boxNum",
							String.valueOf(testGoods.getBoxNum()));
					return response;
				}
			}

			// generate openCode
			String openCode = null;
			do {
				openCode = GenerateRandNumHelper.generate(6);
			} while (goodsDao.isExistGetCode(openCode)
					|| goodsDao.isExistOpenCode(openCode));

			Date now = new Date();
			Timestamp bookingTime = new Timestamp(now.getTime());
			Timestamp deadTime = new Timestamp(TimeHelper.getDeadTime(now,
					period));

			Goods goods = new Goods();
			goods.setTerminalId(terminalId);
			goods.setBoxNum(boxNum);
			goods.setOrderNo(orderNo);
			goods.setBookingTime(bookingTime);
			goods.setDeadTime(deadTime);
			goods.setUserMobileNum(userMobileNum);
			goods.setCourierMobileNum(mobileNum);
			goods.setOpenCode(openCode);
			goods.setStatus(0);
			goods.setAgentId(agent.getId());
			goods.setRemark("0");
			goods.setIsForcedOpen("0");
			goodsDao.save(goods);
			goods = goodsDao.getGoodsByOrderNo(orderNo);
			boxDao.boxToggleAvailable(terminal, String.valueOf(boxNum), 3);
			boxDao.setBoxGoods(terminal.getTerminalID(), boxNum, goods.getId());

			// 等待设备反馈
			Thread.sleep(3000);
			// TimerHelper.isTerminalReceive(orderNo, 3000);
			goods = goodsDao.getGoodsByOrderNo(orderNo);
			if ("1".equals(goods.getRemark())) {
				response.put("responseCode", BOOKING_SUCCESS);
				response.put("response", "预订成功");
				response.put("saveOpenCode", openCode);
				response.put("orderNo", orderNo);
				response.put("boxNum", String.valueOf(boxNum));
				response.put("cancelTime",
						String.valueOf(goods.getDeadTime().getTime() / 1000));
				return response;
			} else {
				response.put("responseCode", BOOKING_SUCCESS_WAITTING);
				response.put("response", "预定请求已接收，等待反馈。");
				return response;
			}
		} catch (Exception e) {
			e.printStackTrace();
			response.put("responseCode", PARAM_ERROR);
			response.put("response", "参数错误");
			return response;
		}
	}

	/**
	 * 查询订单的箱格状态
	 * 
	 * @param partnerID
	 * @param sign
	 * @param orderNo
	 * @param timestamp
	 * @return
	 */
	@RequestMapping("QueryBoxStatus")
	@ResponseBody
	public Map<String, String> queryboxstatus(
			@RequestParam("partnerID") String partnerID,
			@RequestParam("sign") String sign,
			@RequestParam("orderNo") String orderNo,
			@RequestParam("timestamp") String t) {
		HashMap<String, String> response = new HashMap<String, String>();
		try {

			// 参数检查
			long timestamp = Long.parseLong(t);
			// 验证请求是否超时
			if (TimeHelper.isNowLate(timestamp, 5)) {
				response.put("responseCode", TIME_OUT);
				response.put("response", "请求已超时");
				return response;
			}
			// varify agent
			Agent agent = agentDao.findByPartnerId(partnerID);
			agent.setTimestamp(timestamp);
			if (agent == null || !agent.varify(sign)) {
				response.put("responseCode", AUTH_ERROR);
				response.put("response", "身份校验失败");
				return response;
			}

			Goods goods = goodsDao.getGoodsByOrderNo(orderNo);
			;
			if (goods == null) {
				response.put("responseCode", QUERY_FAILURE);
				response.put("response", "查询失败(订单号未知)");
				return response;
			} else if (!isTerminalBelong(goods.getTerminalId(), agent.getId())) {
				response.put("responseCode", QUERY_FAILURE);
				response.put("response", "查询失败(设备不在管辖范围或不存在)");
				return response;
			} else {
				response.put("responseCode", QUERY_SUCCESS);
				response.put("boxStatus", String.valueOf(goods.getStatus()));
				response.put("response", "查询成功");
				return response;
			}
		} catch (Exception e) {
			e.printStackTrace();
			response.put("responseCode", PARAM_ERROR);
			response.put("response", "参数错误");
			return response;
		}
	}

	/**
	 * 查询设备列表
	 * 
	 * @param partnerID
	 * @param sign
	 * @param timestamp
	 * @return
	 */
	@RequestMapping("QueryDevList")
	@ResponseBody
	public Map<String, Object> queryDevList(
			@RequestParam("partnerID") String partnerID,
			@RequestParam("sign") String sign,
			@RequestParam("timestamp") String t) {
		HashMap<String, Object> response = new HashMap<String, Object>();
		ArrayList<DevList> devLists = null;

		try {
			// 检查参数
			long timestamp = Long.parseLong(t);
			// 验证请求是否超时
			if (TimeHelper.isNowLate(timestamp, 5)) {
				response.put("responseCode", TIME_OUT);
				response.put("response", "请求已超时");
				return response;
			}
			// varify agent
			Agent agent = agentDao.findByPartnerId(partnerID);
			agent.setTimestamp(timestamp);
			if (agent == null || !agent.varify(sign)) {
				response.put("responseCode", AUTH_ERROR);
				response.put("response", "身份校验失败");
				return response;
			}

			devLists = terminalDao.getDevLisByAgentId(agent.getId());
			if (devLists.size() == 0) {
				response.put("responseCode", QUERY_FAILURE);
				response.put("response", "查询失败(无隶属该代理商的设备)");
				return response;
			}
		} catch (Exception e) {
			e.printStackTrace();
			response.put("responseCode", PARAM_ERROR);
			response.put("response", "参数错误");
			return response;
		}
		response.put("responseCode", QUERY_SUCCESS);
		response.put("devList", devLists);
		response.put("response", "查询成功");
		return response;
	}

	/**
	 * 查询箱格类型及使用情况
	 * 
	 * @param partnerID
	 * @param sign
	 * @param deviceSeq
	 * @param timestamp
	 * @return
	 */
	@RequestMapping("QueryBoxTypeStatus")
	@ResponseBody
	public Map<String, Object> queryBoxTypeStatus(
			@RequestParam("partnerID") String partnerID,
			@RequestParam("sign") String sign,
			@RequestParam("deviceSeq") String deviceSeq,
			@RequestParam("timestamp") String t) {
		HashMap<String, Object> response = new HashMap<String, Object>();
		ArrayList<BoxTypeStatusList> boxTypeStatusLists = new ArrayList<BoxTypeStatusList>();
		try {
			// 检查参数
			long timestamp = Long.parseLong(t);
			if(deviceSeq.length()!=12){
				throw new Exception();
			}
			int terminalId = Integer.parseInt(deviceSeq.substring(2));// 一期暂用terminalId，转换去掉YB留下整数
			// 验证请求是否超时
			if (TimeHelper.isNowLate(timestamp, 5)) {
				response.put("responseCode", TIME_OUT);
				response.put("response", "请求已超时");
				return response;
			}
			// varify agent
			Agent agent = agentDao.findByPartnerId(partnerID);
			agent.setTimestamp(timestamp);
			if (agent == null || !agent.varify(sign)) {
				response.put("responseCode", AUTH_ERROR);
				response.put("response", "身份校验失败");
				return response;
			}

			if (!isTerminalBelong(terminalId, agent.getId())) {
				response.put("responseCode", QUERY_FAILURE);
				response.put("response", "查询失败(设备不在管辖范围或不存在)");
				return response;
			}

			for (int i = 1; i <= 4; i++) {
				BoxTypeStatusList boxTypeStatusList = new BoxTypeStatusList();
				boxTypeStatusList.setBoxTypeID(String.valueOf(i));
				boxTypeStatusList.setBoxTypeAvailableNum(String.valueOf(boxDao
						.getBoxTypeStatusList(terminalId, i, 0)));
				boxTypeStatusList
						.setBoxTypeNotAvailableNum(String.valueOf(boxDao
								.getBoxTypeStatusList(terminalId, i, 1)));
				boxTypeStatusLists.add(boxTypeStatusList);
			}
			if (boxTypeStatusLists.size() == 0) {
				response.put("responseCode", QUERY_FAILURE);
				response.put("response", "查询失败(不存在该序列号)");
				return response;
			} else {
				response.put("responseCode", QUERY_SUCCESS);
				response.put("boxTypeStatusList", boxTypeStatusLists);
				response.put("response", "查询成功");
				return response;
			}
		} catch (Exception e) {
			e.printStackTrace();
			response.put("responseCode", PARAM_ERROR);
			response.put("response", "参数错误");
			return response;
		}

	}

	/**
	 * 检查设备是否在管辖范围
	 * 
	 * @param terminalId
	 * @param agentId
	 * @return
	 */
	private boolean isTerminalBelong(int terminalId, int agentId) {
		int branchID = terminalDao.getTerminalBranchId(terminalId);
		ArrayList<Branch> branchs = branchDao.getByAgentId(agentId);
		boolean belong = false;
		for (Branch b : branchs) {
			if (b.getId() == branchID) {
				belong = true;
				break;
			}
		}
		return belong;
	}

	/**
	 * 箱格取消预定接口
	 * 
	 * @param partnerID
	 * @param sign
	 * @param orderNo
	 * @param timestamp
	 * @return
	 */
	@RequestMapping("BoxCancelOrder")
	@ResponseBody
	public Map<String, String> boxCancelOrder(
			@RequestParam("partnerID") String partnerID,
			@RequestParam("sign") String sign,
			@RequestParam("orderNo") String orderNo,
			@RequestParam("timestamp") String t) {
		HashMap<String, String> response = new HashMap<String, String>();
		Goods goods = null;

		try {
			// 检查参数
			long timestamp = Long.parseLong(t);
			// 验证请求是否超时
			if (TimeHelper.isNowLate(timestamp, 5)) {
				response.put("responseCode", TIME_OUT);
				response.put("response", "请求已超时");
				return response;
			}
			// varify agent
			Agent agent = agentDao.findByPartnerId(partnerID);
			agent.setTimestamp(timestamp);
			if (agent == null || !agent.varify(sign)) {
				response.put("responseCode", AUTH_ERROR);
				response.put("response", "身份校验失败");
				return response;
			}

			goods = goodsDao.getGoodsByOrderNo(orderNo);
			if (goods == null) {
				response.put("responseCode", CANCELORDER_FAILURE_NOORDER);
				response.put("response", "取消预订失败（未找到订单或箱格）");
				response.put("orderNo", orderNo);
				return response;
			} else {
				if (!isTerminalBelong(goods.getTerminalId(), agent.getId())) {
					response.put("responseCode", QUERY_FAILURE);
					response.put("response", "查询失败(设备不在管辖范围或不存在)");
					return response;
				}
				if (goods.getStatus() != 0) {
					response.put("responseCode", CANCELORDER_FAILURE_NOBOOK);
					response.put("response", "取消预订失败（订单无效、不处于预订状态）");
					response.put("orderNo", orderNo);
					return response;
				} else {
					// 取消预定，标记物品，释放箱格
					// goodsDao.updateStatusByOrderNo(orderNo, "7", "2")&&
					// boxDao.updateBoxStatus(goods.getTerminalId(),goods.getBoxNum(),
					// 0)
					if (goodsDao.updateRemarkByOrderNo(orderNo, "2")) {
						response.put("responseCode", CANCELORDER_SUCCESS);
						response.put("response", "取消预订指令下发成功，等待执行");
						response.put("orderNo", orderNo);
					} else {
						response.put("responseCode", PARAM_ERROR);
						response.put("response", "参数出错");
						response.put("orderNo", orderNo);
					}
					return response;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			response.put("responseCode", PARAM_ERROR);
			response.put("response", "参数出错");
			response.put("orderNo", orderNo);
			return response;
		}
	}

	/**
	 * 远程强制开箱
	 * 
	 * @param partnerID
	 * @param sign
	 * @param orderNo
	 * @param timestamp
	 * @return
	 */
	@RequestMapping("ForcedOpenBox")
	@ResponseBody
	public Map<String, String> forcedOpenBox(
			@RequestParam("partnerID") String partnerID,
			@RequestParam("sign") String sign,
			@RequestParam("orderNo") String orderNo,
			@RequestParam("timestamp") String t,
			@RequestParam(value = "cmdEffectiveTime", defaultValue = "5") String effectTime) {
		HashMap<String, String> response = new HashMap<String, String>();
		Goods goods = null;

		try {
			// 检查参数
			long timestamp = Long.parseLong(t);
			// 验证请求是否超时
			if (TimeHelper.isNowLate(timestamp, 5)) {
				response.put("responseCode", TIME_OUT);
				response.put("response", "请求已超时");
				return response;
			}
			// varify agent
			Agent agent = agentDao.findByPartnerId(partnerID);
			// RequestNotifyThread rnt = new RequestNotifyThread();
			agent.setTimestamp(timestamp);
			if (agent == null || !agent.varify(sign)) {
				response.put("responseCode", AUTH_ERROR);
				response.put("response", "身份校验失败");
				return response;
			}
			int cmdEffectiveTime = Integer.parseInt(effectTime);
			goods = goodsDao.getGoodsByOrderNo(orderNo);
			if (goods == null) {
				response.put("responseCode", COMMAND_FAILURE_NOORDER);
				response.put("response", "命令执行失败（未找到订单）");
				return response;
			} else if (goods.getAgentId() != agent.getId()) {
				response.put("responseCode", COMMAND_FAILURE_NOORDER);
				response.put("response", "命令执行失败（单号不在管辖范围）");
				return response;
			} else if (TimeHelper.isTerminalOff(terminalDao.get(
					goods.getTerminalId()).getLoginTime())) {
				response.put("responseCode", COMMAND_FAILURE_NOORDER);
				response.put("response", "命令执行失败（设备不在线）");
				goodsDao.updateForcedOpenByOrderNo(orderNo, "0");
				return response;
			} else if ("1".equals(goods.getIsForcedOpen())) {
				response.put("responseCode", COMMAND_SUCCESS);
				response.put("response", "命令已经接收，请勿重复请求。");
				return response;
			} else {
				if (goods.getStatus() == 0) {
					response.put("responseCode", COMMAND_FAILURE_NOGOODS);
					response.put("response", "命令执行失败（订单还未有物品）");
					return response;
				} else if (goods.getStatus() == 6) {
					response.put("responseCode", COMMAND_FAILURE_TIMEOUT);
					response.put("response", "命令执行失败（订单超时）");
					return response;
				} else if (goods.getStatus() == 4) {
					response.put("responseCode", COMMAND_FAILURE_GOODSGETTED);
					response.put("response", "命令执行失败（订单物品已被取走）");
					return response;
				} else {
					if (goods.getStatus() == 3||goods.getStatus() == 8) {
						if (boxDao.forceOpenBox(goods.getTerminalId(),
								goods.getBoxNum(), cmdEffectiveTime)
								&& goodsDao.updateForcedOpenByOrderNo(orderNo,
										"1")) {
							// rnt.setSign(agent.getSign(timestamp));
							// rnt.setTimestamp(String.valueOf(timestamp));
							// rnt.setOrderNum(goods.getOrderNo());
							// rnt.setUrl(agent.getFeedbackUrl());
							// rnt.setBoxNum(String.valueOf(goods.getBoxNum()));
							// rnt.setFuncName("ForcedOpenResult");
							// rnt.setFlag("forceOpen");
							// Thread thread = new Thread(rnt);
							// thread.start();
							response.put("responseCode", COMMAND_SUCCESS);
							response.put("response", "命令已经接收等待执行");
							return response;
						} else {
							throw new Exception();
						}
					} else {
						response.put("responseCode", COMMAND_FAILURE_NOGOODS);
						response.put("response", "命令执行失败（订单还未有物品）");
						return response;
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			response.put("responseCode", PARAM_ERROR);
			response.put("response", "参数错误");
			response.put("orderNo", orderNo);
			return response;
		}
	}
	
	@RequestMapping("ResetBox")
	@ResponseBody
	public Map<String, String> resetBox(
			@RequestParam("partnerID") String partnerID,
			@RequestParam("sign") String sign,
			@RequestParam("type") String type,
			@RequestParam("itemNum") String itemNum,
			@RequestParam("timestamp") String t) {
		HashMap<String, String> response = new HashMap<String, String>();
		try {
			// 参数检查
			long timestamp = Long.parseLong(t);
			// 验证请求是否超时
			if (TimeHelper.isNowLate(timestamp, 5)) {
				response.put("responseCode", TIME_OUT);
				response.put("response", "请求已超时");
				return response;
			}
			// varify agent
			Agent agent = agentDao.findByPartnerId(partnerID);
			agent.setTimestamp(timestamp);
			if (agent == null || !agent.varify(sign)) {
				response.put("responseCode", AUTH_ERROR);
				response.put("response", "身份校验失败");
				return response;
			}
			if("0".equals(type)){
				Goods goods = goodsDao.getGoodsByOrderNo(itemNum);
				if (goods == null||(goods.getStatus()!=5&&goods.getStatus()!=4)) {
					response.put("responseCode", RESET_FAILURE);
					response.put("response", "重置失败(订单号未知或物品未取)");
					return response;
				} else if (!isTerminalBelong(goods.getTerminalId(), agent.getId())) {
					response.put("responseCode", RESET_FAILURE);
					response.put("response", "重置失败(设备不在管辖范围或不存在)");
					return response;
				} else {
					boxDao.boxToggleAvailable(terminalDao.get(goods.getTerminalId()), goods.getBoxNum()+"", 1);
					boxDao.setBoxGoods(goods.getTerminalId(), goods.getBoxNum(), goods.getId());
					goodsDao.resetByOrderNo(itemNum, "3", "6");
					response.put("responseCode", RESET_SUCCESS);
					response.put("response", "重置成功");
					return response;
				}
			}else if("1".equals(type)){
				Parcel parcel = parcelDao.queryLatestParcel(itemNum);
				if (parcel == null||parcel.getStatus()!=1) {
					response.put("responseCode", RESET_FAILURE);
					response.put("response", "重置失败(订单号未知或包裹未取)");
					return response;
				} else if (!isTerminalBelong(parcel.getTerminalId(), agent.getId())) {
					response.put("responseCode", RESET_FAILURE);
					response.put("response", "重置失败(设备不在管辖范围或不存在)");
					return response;
				} else {
					parcelDao.updateParcelFlag(parcel.getId(), 3);
					response.put("responseCode", RESET_SUCCESS);
					response.put("response", "重置成功");
					return response;
				}
			}else{
				response.put("responseCode", PARAM_ERROR);
				response.put("response", "参数错误");
				return response;
			}
		} catch (Exception e) {
			e.printStackTrace();
			response.put("responseCode", PARAM_ERROR);
			response.put("response", "参数错误");
			return response;
		}
	}
	
}
